<?php
/**
 * Created by PhpStorm.
 * 商家信息
 * User: caicm
 * Date: 2017/6/14
 * Time: 17:51
 */

namespace WMApi\Controller;


use WMApi\Model\WmOrderInfoModel;
use WMApi\Model\WmSellerAccountRecordModel;
use WMApi\Model\WmSellerFreezeRecordModel;
use WMApi\Model\WmSellerModel;
use WMApi\Service\SellerStoreService;

class SellerController extends SellerBaseController {

    /**
     * 商家账户余额操作记录
     * Created By caicm
     * @param int page 分页
     */
    public function get_account_record_list(){
        $page = I('post.page', 1, 'int');
        $account_model = new WmSellerAccountRecordModel();

        $record_count = $account_model->find_record_count($this->seller_id);

        $data = show_page($record_count, $page);
        $record_list = $account_model->find_record_list($this->seller_id, $data['firstpage'].','.$data['pagesize']);
        foreach ($record_list as $key=>$value){
            $record_list[$key]['add_time'] = get_date($value['add_time']);
        }
        $data['record_list'] = $record_list;
        if($data['record_list']){
            returnApiSuccess($data);
        }else{            returnApiError('无数据');
        }

    }

    /**
     * 商家冻结账户操作记录
     * Created By caicm
     * @param int page 分页
     */
    public function get_freeze_record(){
        $page = I('post.page', 1, 'int');
        $account_model = new WmSellerFreezeRecordModel();

        $record_count = $account_model->find_record_count($this->seller_id);

        $data = show_page($record_count, $page);
        $record_list = $account_model->find_record_list($this->seller_id, $data['firstpage'].','.$data['pagesize']);
        foreach ($record_list as $key=>$value){
            $record_list[$key]['add_time'] = get_date($value['add_time']);
        }
        $data['record_list'] = $record_list;
        if($data['record_list']){
            returnApiSuccess($data);
        }else{
            returnApiError('无数据');
        }
    }

    /**
     * 我的页面接口
     * Created By caicm
     */
    public function mine(){
        $store_service = new SellerStoreService();
        $seller_model = new WmSellerModel();
        $oder_model = new WmOrderInfoModel();

        $data['store_info'] = $store_service->get_default_store($this->seller_id);

        $seller_info = $seller_model->find_seller_info($this->seller_id);
        $data['account_money'] = $seller_info['account_money'];                     //账户余额
        $data['freeze_money'] = $seller_info['freeze_money'];                       //冻结余额
        $unavailable_money = $oder_model->get_unavailable_money($this->seller_id);          //未结算金额

        $data['unavailable_money'] = $unavailable_money ? $unavailable_money : '0.00';
        returnApiSuccess($data);

    }

}